package pri.hillchen.std.concurrent.chapter5;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author:hillchen
 * @DESCRIPTION:
 * @Date: Created in 10:41 2018/2/7 0007.
 */
public class ConcurrentHashMapIteratorDemo {
    public static void main(String[] args){
        final ConcurrentHashMap<Integer,Integer> concurrentHashMap = new ConcurrentHashMap<Integer, Integer>();
        for(int i = 0; i<50;i++){
            concurrentHashMap.put(i,i);
        }

        Thread removeElement = new RemoveLastElementRunable(concurrentHashMap.entrySet()) {
            void removeElement(Collection collection, int index) {
                concurrentHashMap.remove(index);
            }
        };

        Thread printElement = new PrintElementRunable<Map.Entry<Integer,Integer>>(concurrentHashMap.entrySet()) {
            void printlnElement(Map.Entry<Integer,Integer> o) {
                System.out.println(o.getKey()+":"+o.getValue());
            }
        };

        removeElement.start();
        printElement.start();
    }
}
